package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TravelPaper;
import cn.wolfcode.trip.base.domain.TravelQuestion;
import cn.wolfcode.trip.base.mapper.TravelQuestionMapper;
import cn.wolfcode.trip.base.query.TravelQuestionQuery;
import cn.wolfcode.trip.base.service.ITravelPaperService;
import cn.wolfcode.trip.base.service.ITravelQuestionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TravelQuestionServiceImpl implements ITravelQuestionService{

    @Autowired
    private TravelQuestionMapper travelQuestionMapper;

    @Override
    public PageInfo selectForList(TravelQuestionQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(), qo.getOrderBy());
        List<TravelQuestion> list = travelQuestionMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void save(TravelQuestion travelQuestion) {
        travelQuestion.setReleaseTime(new Date());
        travelQuestion.setState(0);
        travelQuestionMapper.insert(travelQuestion);
    }

    @Override
    public List<TravelQuestion> selectAll() {
        return travelQuestionMapper.selectAll();
    }

    @Override
    public List<TravelQuestion> getQuestions(int state) {
        return travelQuestionMapper.travelQuestionsByState(state);
    }
}
